<?php
	session_start();
	require('Gen_Scripts/gen_functions.php');
	
	dblogin();
	$query=
	"select n.gid, n.new 
	   from NOTES n 
	  where pid = ".$_SESSION['USERNUM'];
	$result = mysql_query($query);
	while($row = mysql_fetch_array($result)){
		if($row['new'] == 'Y'){
			$discussion[] = $row['gid'];
		}		
	}
	
	$query=
	"select g.gameid, g.game, v.vote, g.owner
	   from GAMES g
	   left outer join GAME_VOTE v
		 on g.gameid = v.gameid
		 and v.player = ".$_SESSION['USERNUM']."
	  where v.vote is null;";
	$result = mysql_query($query);
	while($row = mysql_fetch_array($result)){
		$games[] = $row['game'];
	}	
	
?>
<script type="text/javascript">
$(document).ready(function(){

	$('#popup_ajax').localScroll();

	$('.close').click(function(){
		$('#popup_ajax').fadeOut();
	});

<?php if(count($discussion) > 0|| count($games) > 0){?>
	$('#popup_ajax').fadeIn();
<?php }else{?>
	$('#popup_ajax').hide();
<?php } ?>
	
});
</script>


<?php
if(count($discussion) > 0|| count($games) > 0){
	/* Notify Me! */
?>

<h1> You have <?php echo count($discussion)+count($games); ?> new notifications! <input type="button" title="close" class="close" value="X" name="close"/>
</h1>
	<?php
	if(count($discussion) > 0){
		/* Theres some disccussions to display */
		foreach($discussion as $gameid){
	?>
			<a class="local" href="index.php#gamevote" > New discussion for <?php echo print_gamename($gameid); ?></a>
	<?php
		}
	}
	if(count($games) > 0){
	?>
		<a class="local" href="index.php#gamevote" > You have <?php echo count($games); ?> unvoted <?php if(count($games) == 1){echo 'game!';}else{echo 'games!';} ?></a>
	<?php
	}
	?>
	

<?php 
}
?>





















